package ninja.awesome.game.gameobject;

import java.util.Random;

import ninja.awesome.framework.Graphics;
import ninja.awesome.framework.Image;
import ninja.awesome.framework.impl.AndroidGame;
import ninja.awesome.game.MainGameScreen;
import ninja.awesome.game.compat.Rectangle;
import ninja.awesome.game.main.Animation;
import ninja.awesome.game.main.Controller;
import ninja.awesome.game.main.Sprites;

public class Road extends GameObj {
	private static final String TAG = Road.class.getSimpleName();

	private Image[] road;

	private int ticks = 0;
	private int timer = 0;
	private int Stage = 0; // the building shall be spawn depending on the
							// number stage.

	// added for new data field for boss.

	private int whatRoad = 0;

	private int imageNumber = 1;
	private int left = 0;
	private int right = 1;
	private int imageWidth = 1000;

	private String direction = "left"; // I make a boss to move aroud easier!
										// New Source Code Attention!
	Animation anim;
	Random r = new Random();
	MainGameScreen game;
	Sprites s;
	Controller c;

	public Road(int x, int y, MainGameScreen game, Controller c, Sprites s) {
		super(x, y);
		this.s = s;
		this.c = c;
		this.game = game;
		//whatRoad = r.nextInt(2);
		whatRoad = 0;
		road = s.getRoad(whatRoad);
		anim = new Animation(0, road[0], AndroidGame.ROAD_HEIGHT, imageWidth, imageNumber, whatRoad);
	}

	public void update() {
//		if (this.getX() <= -500)
//			game.setEnemy_Spawn(true);
//
//		if (game.getRoad_Block()) {
//			right = 0; // to make road not movable! going right
//		} else
//			right = 1;

//		if (game.getNinja().getDirection().equals("left")) {
//			Log.w(TAG, "Ninja Left, speedX = " + game.getNinja().getSpeedX());
//			xLoc -= game.getNinja().getSpeedX() * 1;
//			if (xLoc > NinjaGame.WIDTH) {
//				c.removeRoad(this);
//			}
//		} else if (game.getNinja().getDirection().equals("right")) {
//			Log.w(TAG, "Ninja right, speedX = " + game.getNinja().getSpeedX());
//			xLoc -= game.getNinja().getSpeedX() * right;
//			if (xLoc < -imageWidth) {
//				c.removeRoad(this);
//			}
//		}
		xLoc -= game.getNinja().getSpeedX();
//		if (xLoc < -2000) {
//			c.spawnRoad(2);
//			c.removeRoad(this);
//		} else if (xLoc > 2000) {
//			c.spawnRoad(-2);
//			c.removeRoad(this);
//		}
	}

	public void draw(Graphics g) {
		// anim.drawAnimation(g, xLoc, yLoc);
		g.drawImage(road[0], xLoc, yLoc, xLoc + imageWidth, yLoc + AndroidGame.ROAD_HEIGHT, 4, 0, imageWidth, AndroidGame.ROAD_HEIGHT);
	}

	public Rectangle getBounds() {
		return new Rectangle(xLoc, yLoc, 1000, AndroidGame.ROAD_HEIGHT);
	}

	public int getX() {
		return this.xLoc;
	}

	public int getY() {
		return this.yLoc;
	}

}
